int* spiralOrder(int** matrix, int matrixSize, int* matrixColSize, int* returnSize){
           int a,b,c,d,j=0;
    a=0;b=0;c=matrixSize-1;d=* matrixColSize-1;
       if (matrixSize == 0 || * matrixColSize == 0) {
        *returnSize = 0;
        return NULL;
    }
       int rows = matrixSize,columns=* matrixColSize;
       int total = rows * columns;
       int* order = malloc(sizeof(int) * total);
       *returnSize = 0;

   while(a<c&&b<d){
        int m=b,n=a;
        while(m<d){
            order[(*returnSize)++]=matrix[a][m];
            m++;
        }
        while(n<c){
            order[(*returnSize)++]=matrix[n][d];
            n++;
        }
        while(m>b){
            order[(*returnSize)++]=matrix[c][m];
            m--;
        }
        while(n>a){
            order[(*returnSize)++]=matrix[n][b];
            n--;
        }
        a++;b++;c--;d--;
    }
    if(a==c){    
        for(int i=b;i<=d;i++){
            order[(*returnSize)++]=matrix[a][i];
        }
    }
    else if(b==d){
        for(int i=a;i<=c;i++){
            order[(*returnSize)++]=matrix[i][b];
    }
  }
    return order;
}
